<html>
<head><meta charset="utf-8"><title>Arc::clone(&amp;arc) vs arc.clone() · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Arc.3A.3Aclone(.26arc).20vs.20arc.2Eclone().html">Arc::clone(&amp;arc) vs arc.clone()</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="199993204"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Arc%3A%3Aclone%28%26arc%29%20vs%20arc.clone%28%29/near/199993204" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Poliorcetics <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Arc.3A.3Aclone(.26arc).20vs.20arc.2Eclone().html#199993204">(Jun 06 2020 at 21:07)</a>:</h4>
<p>In the file <code>src/libstd/sync/condvar.rs</code> this code is used in examples:</p>
<div class="codehilite"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">pair</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Arc</span>::<span class="n">new</span><span class="p">((</span><span class="n">Mutex</span>::<span class="n">new</span><span class="p">(</span><span class="kc">false</span><span class="p">),</span><span class="w"> </span><span class="n">Condvar</span>::<span class="n">new</span><span class="p">()));</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">pair2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">pair</span><span class="p">.</span><span class="n">clone</span><span class="p">();</span><span class="w"></span>
</code></pre></div>


<p>Would it not be better for it to use the <code>Arc::clone(&amp;pair)</code> format instead, to promote the recommended form ?</p>



<a name="199993428"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Arc%3A%3Aclone%28%26arc%29%20vs%20arc.clone%28%29/near/199993428" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Arc.3A.3Aclone(.26arc).20vs.20arc.2Eclone().html#199993428">(Jun 06 2020 at 21:14)</a>:</h4>
<p>there is no formal recommendation to use Arc::clone(&amp;value) afaik</p>



<a name="199993502"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Arc%3A%3Aclone%28%26arc%29%20vs%20arc.clone%28%29/near/199993502" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Poliorcetics <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Arc.3A.3Aclone(.26arc).20vs.20arc.2Eclone().html#199993502">(Jun 06 2020 at 21:16)</a>:</h4>
<p>It is used in the example for the clone impl <a href="https://doc.rust-lang.org/stable/std/sync/struct.Arc.html#impl-Clone">https://doc.rust-lang.org/stable/std/sync/struct.Arc.html#impl-Clone</a></p>
<p>It's also said in the book: <a href="https://doc.rust-lang.org/stable/book/ch15-04-rc.html?highlight=Rc::clone#using-rct-to-share-data">https://doc.rust-lang.org/stable/book/ch15-04-rc.html?highlight=Rc::clone#using-rct-to-share-data</a></p>
<blockquote>
<p>We could have called a.clone() rather than Rc::clone(&amp;a), but Rust’s convention is to use Rc::clone in this case.</p>
</blockquote>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>